﻿//引擎主程序
//本文件由：贺镇涛（2021300004071）负责
#include"Mathtoys.h"
using namespace std;

//负责界面交互，获取输入s,传递给mode_in()，返回并输出out.
string mode = "BASIC";			//负责储存模式,缺省为BASIC
string tips = "";				//负责显示前导提示，默认为空。
int main()
{
	string s;					//用于获取输入
#if  _DEBUG
	cout << "Debug mode!!!" << endl;//为了单步调试的时候方便
#else
	cout << "MATHTOYS,A SMALL (DEVELOPING) PROGRAM POWERED BY 贺镇涛 高肇鸿 姚凯文 周博儒 WHU G2021" << endl;
	cout << "MATHTOYS is a simple calculator.\nType \"man\" or \"help\" for more guidance." << endl;
#endif //  _DEBUG
	while (true)
	{
		cout << tips;
		cout << "<MATHTOYS:\\" << mode << ">";
		getline(cin, s);//疑点：为什么从子程序返回后，getline的第一个s是""？
		if (s == "exit" || s == "Exit" || s == "EXIT") { tips = ""; return 0; }							//退出程序
		else if (s == "trans" || s == "Trans" || s == "TRANS")
		{
			numer2();
			continue;
		}
		else if (s == "basic" || s == "Basic" || s == "BASIC")
		{
			mode = "BASIC";
			tips = "";
			continue;
		}
		else if (s == "mat" || s == "Mat" || s == "MAT")
		{
			cout << "<MATHTOYS:\\MAT>\n";
			matanddet("");
		}
		else if (s == "clear" || s == "cls")
		{
			printf("\033c");
			continue;
		}
		else if (s == "shell" || s == "Shell" || s == "SHELL") { mode = "SHELL"; continue; }
		else if (s == "man" || s == "Man" || s == "MAN" || s == "help" || s == "Help" || s == "HELP") { Text_print("Readme.txt"); continue; }
		string out;
		if (s != "")
		{
			out = mode_in(s);
			/*去除小数点后多余的零*/
			RemoveZero(&out);
			cout << out << endl;
		}
	}
}

string mode_in(const string& s)
{
	string out;
	if (mode == "BASIC")out = basic(s);
	if (mode == "SHELL") shell(s);
	return out;
}